package com.auntvt.timo.jpax.core.quick.model;

import com.auntvt.timo.jpax.core.quick.enums.MatcherType;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.EnumUtils;

import java.util.LinkedHashMap;

/**
 * 匹配规则模型
 *
 * @author 小懒虫 <auntvt@163.com>
 * @date 2021/7/31
 */
@Data
public class Matcher<T> {

    /**
     * 参数对象
     */
    private T params;

    /**
     * 匹配规则列表
     */
    private Rules rules;

    public Matcher() {
    }

    public Matcher(T params, Rules rules) {
        this.params = params;
        this.rules = rules;
    }

    /**
     * 添加规则项
     */
    public void put(String name, MatcherType type) {
        rules.put(name, type);
    }

    /**
     * 添加规则项
     */
    public void put(String name, String type) {
        MatcherType matcherType = EnumUtils.getEnumIgnoreCase(MatcherType.class, type, MatcherType.EQ);
        rules.put(name, matcherType);
    }

    /**
     * 匹配规则
     */
    @EqualsAndHashCode(callSuper = true)
    @Data
    public static class Rules extends LinkedHashMap<String, MatcherType> {
    }
}
